package shili;

import java.util.concurrent.*;

public class executor {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(4);
        //构造方法的数字，就是拆分出来的任务个数
        CountDownLatch count = new CountDownLatch(20);
        for (int i = 0; i < 20; i++) {
            int id = i;
            executorService.submit(()->{
                System.out.println("下载任务"+id+"开始执行");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("下载任务"+id+"结束执行");
                //完毕 over！！！
                count.countDown();
            });
        }
        //当count收到了20个完成，所有任务就都完成了
        //await=>all wait
        count.await();
        System.out.println("所有任务都完成");
    }
}
